import { Injectable } from '@nestjs/common';
import actionBuilder from 'libs/common/utils/actionBuilder';
import { NacosNamingClientService } from 'libs/nacos/nacosNamingClient.service';

@Injectable()
export class GatewayService {
  private action = actionBuilder({
    timeout: 30 * 1000,
  });

  constructor(private nacosNamingClientService: NacosNamingClientService) {}

  async getOneHostPath(serviceName: string, groupName?: string) {
    const host = await this.nacosNamingClientService.selectOneInstances({
      serviceName: serviceName,
      groupName: groupName,
    });
    const path = 'http://' + host.ip + ':' + host.port;
    return path;
  }
}
